package pers.ree.demo.basic;

import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class CharDemo {

    public static void main(String[] args) {
//        char[] chars = {'中', '文', 'a', 'b'};
//        byte[] bytes = String.valueOf(chars).getBytes();

        // 验证一个char占用2个字节
        char c1 = 'A';
        char c2 = '中';
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putChar(c1);
        System.out.println(buffer.position());
        buffer.putChar(c2);
        System.out.println(buffer.position());


//        System.out.println(System.currentTimeMillis());

        printTime();
    }

    private static void printTime() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateString = "1968-10-18 13:15:00";
        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
        // 将LocalDateTime转换为ZonedDateTime对象
        ZonedDateTime zonedDateTime = dateTime.atZone(ZoneId.systemDefault());
//        long timestamp = dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        long timestamp = zonedDateTime.toInstant().toEpochMilli();
        // 打印时间戳
        System.out.println("Timestamp: " + timestamp);
    }
}
